//
//  RegistController.m
//  ChickenA
//
//  Created by 韦显光 on 2018/7/7.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "RegistController.h"
#import "UIButton+countDown.h"
#import "ShowHTMLViewController.h"
@interface RegistController ()
@property (weak, nonatomic) IBOutlet UITextField *tsf1;
@property (weak, nonatomic) IBOutlet UITextField *tsf2;
@property (weak, nonatomic) IBOutlet UITextField *tsf3;
@property (weak, nonatomic) IBOutlet UIButton *xieyiBtno;
@property (weak, nonatomic) IBOutlet UIButton *codeBtno;

@end

@implementation RegistController
- (IBAction)getCodeBtna:(UIButton *)sender {
    if ( [FuncPublic TextFieldisError:_tsf1]) {
        
        [FuncPublic getData:self parameters:@{@"phone":_tsf1.text,@"type":@"1"} RequestUrl:get_code success:^(NSDictionary *acountInfo) {
            [WSProgressHUD showImage:nil status:@"发送成功"];
            [_tsf2 becomeFirstResponder];
            _codeBtno.countDownFormat=@"重新发送%ds";
            [_codeBtno countDownWithTimeInterval:49];
        }];
    }
    
}
- (IBAction)back:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:^{
        
    }];
}

- (IBAction)regBtna:(id)sender {
      if ( [FuncPublic TextFieldisError:_tsf1]||[FuncPublic TextFieldisError:_tsf2]||[FuncPublic TextFieldisError:_tsf3]) {
          [FuncPublic getData:self parameters:@{@"phone":_tsf1.text,@"code":_tsf2.text,@"password":_tsf3.text} RequestUrl:Usersadd success:^(NSDictionary *acountInfo) {
              if ([acountInfo[@"msg"]isEqualToString:@"注册成功"]) {
                  [FuncPublic SaveDefaultInfo:WXGStr(acountInfo[@"result"][@"token"]) Key:@"token"];
                  [FuncPublic SaveDefaultInfo:WXGStr(acountInfo[@"result"][@"uid"]) Key:@"uid"];
                  [self.navigationController popToRootViewControllerAnimated:YES];
                  
              }
               [WSProgressHUD showImage:nil status:acountInfo[@"msg"]];
              
      }];
      }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)btna:(UIButton *)sender {
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ShowHTMLViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ShowHTML"];
    secondViewController.urlStr=@"http://47.106.159.82/user_rules.html";
    [self presentViewController:secondViewController animated:YES completion:^{
        
    }];
}

@end
